﻿using Common;
using login.model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace login.dal
{
    public class LoginInfoDal
    {
        DbContext dbContext = new testContext();
        public people Login(string name,string password)
        {
            string Md5 = Md5Helper.GetMd5(password);
            return dbContext.Set<people>().Where(u => u.username ==name && u.password == Md5).FirstOrDefault();
        }
        public List<people> GetPeople()
        {
            return dbContext.Set<people>().ToList();
        }
        public int Add(people p)
        {
            dbContext.Set<people>().Add(p);
            return dbContext.SaveChanges();
        }

        public int UpdateById(string id)
        {
            people p=dbContext.Set<people>().Where(u => u.username == id).FirstOrDefault();
            p.password ="654321";
            return dbContext.SaveChanges();
        }
        public int DeleteByid(string id)
        {
            people p = dbContext.Set<people>().Where(u => u.username == id).FirstOrDefault();
            dbContext.Set<people>().Remove(p);
            return dbContext.SaveChanges();
        }
    }
}
